package self.hoy.demo.grainmall.product.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import self.hoy.demo.common.utils.PageUtils;
import self.hoy.demo.common.utils.Query;

import self.hoy.demo.grainmall.product.mapper.AttrAttrgroupRelationMapper;
import self.hoy.demo.grainmall.product.entity.AttrAttrgroupRelation;
import self.hoy.demo.grainmall.product.service.AttrAttrgroupRelationService;
import self.hoy.demo.grainmall.product.vo.AttrRelationVo;


@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationMapper, AttrAttrgroupRelation>
        implements AttrAttrgroupRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AttrAttrgroupRelation> page = this.page(
                new Query<AttrAttrgroupRelation>().getPage(params),
                new QueryWrapper<AttrAttrgroupRelation>()
        );

        return new PageUtils(page);
    }

    @Override
    public void saveBatch(List<AttrRelationVo> vos) {
        List<AttrAttrgroupRelation> list = vos.stream().map(v->{
            AttrAttrgroupRelation r = new AttrAttrgroupRelation();
            BeanUtils.copyProperties(v, r);
            return r;
        }).collect(Collectors.toList());
        this.saveBatch(list);
    }

}